package ts.group.webapp.market.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ts.group.webapp.market.dao.IOrderDao;
import ts.group.webapp.market.model.TProductOrder;

import com.starit.common.dao.support.Pagination;
import com.starit.common.dao.support.PaginationRequest;

@Service
public class IOrderService {
	
	@Autowired
	private IOrderDao IOrderDao;
	
	/*根据订单id查询记录*/
	public TProductOrder  getOrderById( Long id){
		return IOrderDao.get(id);
	}
	
	/*查询所有订单*/
	public Pagination<TProductOrder>  findAllForPage(PaginationRequest pageRequest){
		Pagination<TProductOrder> pageList = IOrderDao.findPage(pageRequest);
		return pageList;
	}
	
	/*根据订单编号查询订单*/
	public List<TProductOrder> getOrderByCode(String orderCode){
		if(orderCode == null){
			return new ArrayList<TProductOrder>(0);
		}
		List<TProductOrder> orderList = IOrderDao.findByNamedParam("orderCode", orderCode);
		return orderList;
	}
	
	/*新增订单*/
	public Long createOrder(TProductOrder order){
		Long orderId = IOrderDao.save(order);
		return orderId;
	}
	
	/*更新订单*/
	public void updateOrder(TProductOrder order){
		IOrderDao.update(order);
	}
	
	/*删除订单*/
	public void removeOrder(Long orderId){
		IOrderDao.delete(orderId);
	}
	
	/*根据Hql分页查询*/
	public Pagination<Object> findPageByHQL(String rowSql , 
											String countSql,
											int offset,
											int limit){
		return IOrderDao.findPageByHQL(rowSql, countSql, offset, limit);
	}
}
